package com.linys.scala.study.file

import java.io.PrintWriter
import scala.collection.mutable._
import scala.io.Source

/**
  * Created by admin on 2019/10/15.
  */
object Handle {

  val strSet: Set[String] = Set()

  def main(args : Array[String]) : Unit = {
    var row = 0
    val source = Source.fromFile("dir/cheat/cheat.txt" , "utf-8")
    val now = Source.fromFile("dir/cheat/now.txt" , "utf-8")

    val lineIterator = source.getLines
    val nowLineIterator = now.getLines
    val lines =lineIterator.toArray
    val nowLines =nowLineIterator.toArray
    var i: Integer = 1
    val pattern = "\\D"

    lines.foreach(str => {
      val s = str.replaceAll("\"", "").replaceAll(" ", "").replaceAll(" ","").replaceAll("'","")
      if (!s.isEmpty) {
        var ss: Array[String] = s split "/"
        ss.foreach(sss => {
          if (sss.length == 11) {
            strSet.add(sss)
            // println(i + "===" + sss.length + "===" + sss)
            i = i + 1
          }
        })
      }
    })

    i = 1
    println("====================================有效去重手机号==========================================")
    strSet.foreach(s => {
      println(i + "===去重===" + s)
      i = i + 1
    })
    println("没去重size=== " + strSet.size)
    println("====================================跟系统中的手机号对比过滤==========================================")
    nowLines.foreach(str => {
      if(strSet.contains(str)) {
        println("系统中包含骗子手机号：" + str)
        strSet.remove(str)
      }
    })
    println("去重size=== " + strSet.size)

    val sql = "insert into t_user(mobile,`NAME`, weChat,qq,taobao, note, high_user_id,`limit`,day_limit,browse_day_limit,month_limit,with_limit,`STATUS`, role, create_time) \n" +
      "values ('%s','骗子（手工导入）','骗子微信','骗子QQ','骗子淘宝','骗子号（无法修改）',0,0,0,0,0,99999,'4', '2', now());";
    //写文件
    val out = new PrintWriter("dir/cheat/cheat.sql")
    strSet.foreach(s => {
      out.println(sql.format(s))
    })

    now.close
    source.close
    out.close
  }

}
